import { src, dest } from 'gulp'
import replace from 'gulp-replace'
import plumber from 'gulp-plumber'
import less from 'gulp-less'
import postcss from 'gulp-postcss'
import postcssAssets from 'postcss-assets'  // postcss 资源管理器
import autoprefixer from 'gulp-autoprefixer'
import nodeCssMqPacker from 'node-css-mqpacker'
// import postcssReporter from 'postcss-reporter'  // 用于log提示样式不规范信息
// import stylelint from 'stylelint' // 校验css样式规则
import cssnano from 'gulp-cssnano'  // css 压缩
import gIf from 'gulp-if'

import Config from '../config'

class Style {
  static build() {
    return src(Config.style.src)
      .pipe(plumber(Config.plumber))
      .pipe(less())
      .pipe(postcss([
        postcssAssets(Config.style.postcss.assets),
        autoprefixer(),
        nodeCssMqPacker(Config.style.postcss.nodeCssMqPacker)
      ]))
      .pipe(gIf(Config.isProd, cssnano()))
      .pipe(replace('/frontend/', '../'))
      .pipe(dest(Config.style.dest))
  }
}

export default Style